package com.hogae.capital.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.velocity.runtime.directive.Foreach;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hogae.core.annotation.Log;
import com.hogae.core.core.controller.BaseController;
import com.hogae.core.core.domain.AjaxResult;
import com.hogae.core.enums.BusinessType;
import com.hogae.core.utils.poi.ExcelUtil;

import com.hogae.capital.domain.CapUserWallet;
import com.hogae.capital.service.ICapUserWalletService;
import com.hogae.core.core.page.TableDataInfo;

/**
 * 用户钱包Controller
 *
 * @author hogae
 * @date 2021-02-26
 */
@Api(tags = "用户钱包")
@RestController
@RequestMapping("/capital/wallet")
public class CapUserWalletController extends BaseController {
    @Autowired
    private ICapUserWalletService capUserWalletService;

    /**
     * 查询用户钱包列表
     */
    @ApiOperation("查询用户钱包列表")
    @PreAuthorize("@ss.hasPermi('capital:wallet:list')")
    @GetMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE)
    public TableDataInfo list(CapUserWallet capUserWallet) {
        startPage();
        List<CapUserWallet> list = capUserWalletService.selectCapUserWalletList(capUserWallet);
        return getDataTable(list);
    }

    /**
     * 导出用户钱包列表
     */
    @ApiOperation("导出用户钱包列表")
    @PreAuthorize("@ss.hasPermi('capital:wallet:export')")
    @Log(title = "用户钱包", businessType = BusinessType.EXPORT)
    @GetMapping(value = "/export", produces = MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult export(CapUserWallet capUserWallet) {
        List<CapUserWallet> list = capUserWalletService.selectCapUserWalletList(capUserWallet);
        ExcelUtil<CapUserWallet> util = new ExcelUtil<CapUserWallet>(CapUserWallet.class);
        return util.exportExcel(list, "wallet");
    }

    /**
     * 获取用户钱包详细信息
     */
    @ApiOperation("获取用户钱包详细信息")
    @PreAuthorize("@ss.hasPermi('capital:wallet:query')")
    @GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(capUserWalletService.selectCapUserWalletById(id));
    }

    /**
     * 新增用户钱包
     */
    @ApiOperation("新增用户钱包")
    @PreAuthorize("@ss.hasPermi('capital:wallet:add')")
    @Log(title = "用户钱包", businessType = BusinessType.INSERT)
    @PostMapping(produces = MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult add(@RequestBody CapUserWallet capUserWallet) {
        return toAjax(capUserWalletService.insertCapUserWallet(capUserWallet));
    }

    /**
     * 修改用户钱包
     */
    @ApiOperation("修改用户钱包")
    @PreAuthorize("@ss.hasPermi('capital:wallet:edit')")
    @Log(title = "用户钱包", businessType = BusinessType.UPDATE)
    @PutMapping(produces = MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult edit(@RequestBody CapUserWallet capUserWallet) {
        return toAjax(capUserWalletService.updateCapUserWallet(capUserWallet));
    }

    /**
     * 删除用户钱包
     */
    @ApiOperation("删除用户钱包")
    @PreAuthorize("@ss.hasPermi('capital:wallet:remove')")
    @Log(title = "用户钱包", businessType = BusinessType.DELETE)
    @DeleteMapping(value = "/{ids}", produces = MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult remove(@PathVariable Long[] ids) {

        return toAjax(capUserWalletService.deleteCapUserWalletByIds(ids));
    }
}
